home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
programr
/
utexec2.zip
/
RUN16.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-06
|
2KB
|
131 lines
/* Freely given to the public domain by Timothy A. Anderson */
/* Do what you want with it. */
#include <windows.h>
#define W32SUT_16
#include <w32sut.h>
static HINSTANCE global_hinst;
typedef struct enum_info_struct {
HINSTANCE h_instance;
HWND h_wnd;
HTASK h_task;
} enum_info_type;
static DWORD is_app_running(enum_info_type *p_info)
{
if (p_info->h_wnd == NULL) {
return FALSE;
}
if (!IsWindow(p_info->h_wnd) || !IsTask(p_info->h_task)) {
return FALSE;
}
if (GetWindowWord(p_info->h_wnd, GWW_HINSTANCE) != p_info->h_instance) {
return FALSE;
}
if (GetWindowTask(p_info->h_wnd) != p_info->h_task) {
return FALSE;
}
return TRUE;
}
static int PASCAL enum_wnd_proc(HWND h_wnd, DWORD l_param)
{
HINSTANCE h_instance;
enum_info_type *p_enum_info;
h_instance = GetWindowWord(h_wnd, GWW_HINSTANCE);
p_enum_info = (enum_info_type *)l_param;
if (h_instance == p_enum_info->h_instance) {
p_enum_info->h_wnd = h_wnd;
return FALSE;
}
return TRUE;
}
DWORD __export PASCAL RunThunkInit(UT16CBPROC pfnCB, LPVOID data)
{
return(TRUE);
}
typedef struct run_thunk_data_struct {
char *p_exec;
char *p_data;
} run_thunk_data_type;
DWORD __export PASCAL RunThunkRun(LPVOID pData, DWORD funcode)
{
run_thunk_data_type *p_thunk_data;
enum_info_type *p_enum_info;
FARPROC fp;
UINT rval;
switch(funcode) {
case 0:
return(sizeof(enum_info_type));
break;
case 1:
p_thunk_data = (run_thunk_data_type *)pData;
rval = WinExec(p_thunk_data->p_exec, SW_SHOW);
p_enum_info = (enum_info_type *)p_thunk_data->p_data;
p_enum_info->h_wnd = NULL;
p_enum_info->h_task = NULL;
if (rval < 32) {
p_enum_info->h_instance = NULL;
} else {
p_enum_info->h_instance = (HINSTANCE)rval;
fp = MakeProcInstance(enum_wnd_proc, global_hinst);
EnumWindows(fp, (DWORD)p_enum_info);
FreeProcInstance(fp);
if (p_enum_info->h_wnd != NULL) {
p_enum_info->h_task = GetWindowTask(p_enum_info->h_wnd);
}
}
return((DWORD)rval);
break;
case 2:
return(is_app_running((enum_info_type *)pData));
break;
}
return(0);
}
int CALLBACK LibMain(HINSTANCE hInst,
WORD wDataSeg,
WORD cbHeapSize,
LPSTR lpszCmdLine)
{
if (cbHeapSize) {
UnlockData(0);
}
global_hinst = hInst;
return(TRUE);
}
int CALLBACK WEP(int nParameter)
{
return(TRUE);
}